﻿using System;
#pragma warning disable 649

namespace fastCSharp.code.cSharp.template
{
    class sqlModel : pub
    {
        #region PART CLASS
        /*NOTE*/
        public partial class /*NOTE*/@TypeNameDefinition
        {
            #region IF IsManyPrimaryKey
            /// <summary>
            /// 关键字
            /// </summary>
            [fastCSharp.code.ignore]
            public struct primaryKey : IEquatable<primaryKey>/*IF:Attribute.IsComparable*/, IComparable<primaryKey>/*IF:Attribute.IsComparable*/
            {
                #region LOOP PrimaryKeys
                #region IF XmlDocument
                /// <summary>
                /// @XmlDocument
                /// </summary>
                #endregion IF XmlDocument
                public @MemberType.FullName @MemberName;
                #endregion LOOP PrimaryKeys
                /// <summary>
                /// 关键字比较
                /// </summary>
                /// <param name="other">关键字</param>
                /// <returns>是否相等</returns>
                public bool Equals(primaryKey other)
                {
                    #region NOTE
                    MemberName = null;
                    #endregion NOTE
                    return /*PUSH:PrimaryKey0*/@MemberName/**/.Equals(other.@MemberName)/*PUSH:PrimaryKey0*//*LOOP:NextPrimaryKeys*/ && @MemberName/**/.Equals(other.@MemberName)/*LOOP:NextPrimaryKeys*/;
                }
                /// <summary>
                /// 哈希编码
                /// </summary>
                /// <returns></returns>
                public override int GetHashCode()
                {
                    return /*PUSH:PrimaryKey0*/@MemberName/*PUSH:PrimaryKey0*/.GetHashCode()/*LOOP:NextPrimaryKeys*/ ^ @MemberName/**/.GetHashCode()/*LOOP:NextPrimaryKeys*/;
                }
                /// <summary>
                /// 关键字比较
                /// </summary>
                /// <param name="obj"></param>
                /// <returns></returns>
                public override bool Equals(object obj)
                {
                    return Equals((primaryKey)obj);
                }
                #region IF Attribute.IsComparable
                /// <summary>
                /// 关键字比较
                /// </summary>
                /// <param name="other"></param>
                /// <returns></returns>
                public int CompareTo(primaryKey other)
                {
                    int _value_ = /*PUSH:PrimaryKey0*/@MemberName/**/.CompareTo(other.@MemberName)/*PUSH:PrimaryKey0*/;
                    #region LOOP NextPrimaryKeys
                    if (_value_ == 0)
                    {
                        _value_ = @MemberName/**/.CompareTo(other.@MemberName);
                    #endregion LOOP NextPrimaryKeys
                        #region LOOP NextPrimaryKeys
                    }
                        #endregion LOOP NextPrimaryKeys
                    return _value_;
                }
                #endregion IF Attribute.IsComparable
            }
            #endregion IF IsManyPrimaryKey

            /// <summary>
            /// 数据库表格模型
            /// </summary>
            /// <typeparam name="valueType">表格映射类型</typeparam>
            public abstract class sqlModel<valueType> : @type.FullName
                where valueType : sqlModel<valueType>
            {
                /// <summary>
                /// SQL表格操作工具
                /// </summary>
                protected static readonly fastCSharp.emit.sqlTable<valueType, @type.FullName/*IF:PrimaryKeys.Count*/, @PrimaryKeyType/*IF:PrimaryKeys.Count*/> @SqlTableName = fastCSharp.emit.sqlTable<valueType, @type.FullName/*IF:PrimaryKeys.Count*/, @PrimaryKeyType/*IF:PrimaryKeys.Count*/>.Get();
                #region IF Attribute.LogTcpCallService
                /// <summary>
                /// 日志
                /// </summary>
                protected static fastCSharp.sql.logStream<valueType, @type.FullName> @SqlStreamName;
                #region IF Attribute.IsLogClientQueue
                /// <summary>
                /// 日志处理
                /// </summary>
                /// <param name="onLog"></param>
                [fastCSharp.code.cSharp.tcpMethod(IsServerAsynchronousCallback = true, IsClientCallbackTask = false, IsClientAsynchronous = true, IsClientSynchronous = false, IsKeepCallback = true, Service = "@Attribute.LogTcpCallService")]
                protected static void onSqlLog(Func<fastCSharp.net.returnValue<fastCSharp.sql.logStream<valueType, @type.FullName>.data>, bool> onLog)
                {
                    @SqlStreamName/**/.OnLog(onLog);
                }
                #endregion IF Attribute.IsLogClientQueue
                #region NOT Attribute.IsLogClientQueue
                /// <summary>
                /// 获取日志流缓存数据
                /// </summary>
                /// <returns>日志流缓存数据</returns>
                [fastCSharp.code.cSharp.tcpMethod(IsClientCallbackTask = false, IsClientAsynchronous = true, IsClientSynchronous = false, Service = "@Attribute.LogTcpCallService")]
                protected static fastCSharp.sql.logStream<valueType, @type.FullName>.cacheIdentity getSqlCache()
                {
                    return @SqlStreamName/**/.Cache;
                }
                /// <summary>
                /// 日志处理
                /// </summary>
                /// <param name="ticks">时钟周期标识</param>
                /// <param name="identity">日志编号</param>
                /// <param name="onLog"></param>
                [fastCSharp.code.cSharp.tcpMethod(IsServerAsynchronousCallback = true, IsClientCallbackTask = false, IsClientAsynchronous = true, IsClientSynchronous = false, IsKeepCallback = true, Service = "@Attribute.LogTcpCallService")]
                protected static void onSqlLog(long ticks, int identity, Func<fastCSharp.net.returnValue<fastCSharp.sql.logStream<valueType, @type.FullName>.data>, bool> onLog)
                {
                    @SqlStreamName/**/.OnLog(ticks, identity, onLog);
                }
                #endregion NOT Attribute.IsLogClientQueue
                #region IF sqlStreamMembers.Length
                /// <summary>
                /// 成员加载计数器
                /// </summary>
                protected static readonly fastCSharp.sql.logStream.memberCount @SqlStreamCountName = new fastCSharp.sql.logStream.memberCount(-1/*LOOP:sqlStreamMembers*//*PUSH:Member*/, @MemberIndex/*PUSH:Member*//*LOOP:sqlStreamMembers*/);
                /// <summary>
                /// 计算字段日志流
                /// </summary>
                public struct sqlStreamLoad
                {
                    /// <summary>
                    /// 数据对象
                    /// </summary>
                    internal sqlModel<valueType> _value_;
                    #region LOOP sqlStreamMembers
                    #region PUSH Member
                    private static readonly fastCSharp.code.memberMap<@type.FullName> @MemberMapName = fastCSharp.sql.logStream.CreateMemberMap(@SqlTableName, value => value.@MemberName);
                    #region IF XmlDocument
                    /// <summary>
                    /// @XmlDocument (更新日志流)
                    /// </summary>
                    /// <param name="value"></param>
                    #endregion IF XmlDocument
                    public void @MemberName(@MemberType.FullName value)
                    {
                        #region IF MemberType.IsIEquatable
                        if (!value.Equals(_value_.@MemberName))
                        #endregion IF MemberType.IsIEquatable
                        {
                            _value_.@MemberName = value;
                            @MemberName();
                        }
                    }
                    #region IF XmlDocument
                    /// <summary>
                    /// @XmlDocument (更新日志流)
                    /// </summary>
                    #endregion IF XmlDocument
                    public void @MemberName()
                    {
                        if (@SqlStreamName != null) @SqlStreamName/**/.Update((valueType)_value_, @MemberMapName);
                    }
                    /// <summary>
                    /// @XmlDocument 计算初始化完毕
                    /// </summary>
                    public static void @MemberLoadedMethodName() { @SqlStreamCountName/**/.Load(@MemberIndex); }
                    #endregion PUSH Member
                    #endregion LOOP sqlStreamMembers
                }
                /// <summary>
                /// 计算字段日志流
                /// </summary>
                [fastCSharp.code.ignore]
                public sqlStreamLoad @SqlStreamLoadName
                {
                    get { return new sqlStreamLoad { _value_ = this }; }
                }
                #endregion IF sqlStreamMembers.Length
                #endregion IF Attribute.LogTcpCallService
            }
        }
        #endregion PART CLASS
    }
    /// <summary>
    /// CSharp模板公用模糊类型
    /// </summary>
    internal partial class pub : System.IEquatable<pub>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool Equals(pub other) { return false; }
    }
}
